package mre;

import org.jdom.Element;

import util.XMLWriter;

public class ResourceAllocation {
	public int m_cycle;
	public String m_building;
	public int m_x,m_y;
	public int m_unitID;
	
	public ResourceAllocation(int cycle,String bldg,int x,int y,int unitID) {
		m_cycle = cycle;
		m_building = bldg;
		m_x = x;
		m_y = y;
		m_unitID = unitID;
	}
	
	public void writeXML(XMLWriter w) {
		w.tag("resource-allocation");
		{
			w.tag("cycle", m_cycle);
			w.tag("building", m_building);
			w.tag("x", m_x);
			w.tag("y", m_y);
			w.tag("unit-id", m_unitID);
		}
		w.tag("/resource-allocation");
	}
	
	public static ResourceAllocation loadFromXML(Element e) {
		assert e.getName().equals("resource-allocation") :
			"ResourceAllocation.loadFromXML: Invalid XML Element " +
			e.getName();
		
		int cycle = Integer.parseInt(e.getChild("cycle").getText());
		String building = e.getChild("building").getText();
		int x = Integer.parseInt(e.getChild("x").getText());
		int y = Integer.parseInt(e.getChild("y").getText());
		int unitID = Integer.parseInt(e.getChild("unitID").getText());
		
		return new ResourceAllocation(cycle, building, x, y, unitID);
	}
}
